package com.kly.user.dto.chatter.response;

import com.fqgj.common.utils.StringUtils;
import com.kly.user.dto.vo.UserModelVo;
import lombok.Getter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Getter
public class ChatterModelsUnreadMsgDto implements Serializable {


    private static final long serialVersionUID = -5900870450746193884L;
    public List<ChatterModelsUnreadMsgDtoItem> models = new ArrayList<>();

    public ChatterModelsUnreadMsgDto() {
    }

    public ChatterModelsUnreadMsgDto(List<UserModelVo> userModelVos, Map<String, Integer> modelWithUnreadTotal) {

        userModelVos.forEach(u -> {
            models.add(
                    new ChatterModelsUnreadMsgDtoItem()
                            .setNickName(StringUtils.isEmpty(u.getNickName()) ? " " : u.getNickName())
                            .setToken(u.getToken())
                            .setAvatarUrl(u.getModelAvatarUrl())
                            .setModelCode(u.getModelUserCode())
                            .setUnReadNum(modelWithUnreadTotal.getOrDefault(u.getModelUserCode(), 0))
            );
        });

    }

    public ChatterModelsUnreadMsgDto setModels(List<ChatterModelsUnreadMsgDtoItem> models) {
        this.models = models;
        return this;
    }
}

